package com.training.service;

import com.training.entity.InformationComment;
import com.training.mapper.InformationCommentMapper;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class InformationCommentService {

    private final InformationCommentMapper commentMapper;

    public InformationCommentService(InformationCommentMapper commentMapper) {
        this.commentMapper = commentMapper;
    }

    public void addComment(InformationComment comment) {
        if (comment.getContent() == null || comment.getContent().trim().isEmpty()) {
            throw new IllegalArgumentException("评论内容不能为空。");
        }
        commentMapper.insert(comment);
    }

    public List<InformationComment> getCommentsByInfoId(Long infoId) {
        return commentMapper.findByInfoId(infoId);
    }
}